<?php
/**
* A Auth class
* The Auth includes a User object and handles data to and from it, 
* it checks the state of logged in and logged out.
* @author dmq (master@dmq.se)
*/
class Auth
{
	/**
	* function IsLoggedIn checks if user is logged in by checkning if session user is set.
	* @return boolean true | false depends if $_SESSION['user'] is set.
	*/
	public static function IsLoggedIn()
	{
		return isset( $_SESSION['user'] );
	}
	
	/**
	* function GetUser
	* @return boolean false | User as unserialized depends if the user is logged in.
	*/
	public static function GetUser()
	{
		require_once 'php/obj/User.php';
		return self::IsLoggedIn() ? unserialize( $_SESSION['user'] ) : null;
	}
	
	/**
	* function SetUser
	* @return boolean false | User as serialized depends if the user is logged in.
	*/
	public static function SetUser( $id, $name, $email )
	{
		require_once 'php/obj/User.php';
		$_SESSION['user'] = serialize( new User( $id, $name, $email ) );
	}
	
	public static function LogoutUser()
	{
		if ( isset( $_SESSION['user'] ) )
		{
			unset( $_SESSION['user'] );
			session_destroy();
		}
	}
}
